use std::fmt::Display;
use tokio::sync::mpsc::Sender;

#[derive(Debug)]
pub struct ErrorResult {
    pub code: usize,
    pub message: String,
}

impl Display for ErrorResult {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Error: {} - {}", self.code, self.message)
    }
}

#[derive(Debug, Clone)]
pub struct RequestStruct {
    pub key: String,
    pub addr: String,
    pub access_time: i64,
    pub read: Vec<u8>,
    pub send: Sender<Vec<u8>>,
}

#[derive(Debug, Clone)]
pub struct MiddlewareStruct {
    pub reject_passage: bool,
    pub reject_type: MiddlewareRejectType,
    pub request: RequestStruct,
}

impl MiddlewareStruct {
    pub fn new(params: RequestStruct) -> Self {
        Self {
            reject_passage: false,
            reject_type: MiddlewareRejectType::None,
            request: params,
        }
    }
}

#[derive(Debug, Clone)]
pub enum MiddlewareRejectType {
    None,
    Reject,
    RejectAndClose,
}
impl std::fmt::Display for MiddlewareRejectType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            MiddlewareRejectType::None => write!(f, "None"),
            MiddlewareRejectType::Reject => write!(f, "Reject"),
            MiddlewareRejectType::RejectAndClose => write!(f, "RejectAndClose"),
        }
    }
}